import math

from engineUtil import *

class Goal:
    def __init__(self):
        self.name = "UNDEFINED"
        self.priority = 0

    def setPriority(self, position, date):
        print "NOT IMPLEMENTED"

    def takeTimeStep(self, position, activity, dt):
        return position, activity


class GoalWork(Goal):
    def __init__(self):
        self.name = "Work"
        self.position = (20,20)

    def setPriority(self, position, date):
        dt = transportTime(position, self.position)
        dateStart = datetime(date.year, date.month, date.day, 9, 0, 0) - timedelta(hours=dt)
        dateEnd = datetime(date.year, date.month, date.day, 17, 0, 0)
        if date >= dateStart and date <= dateEnd:
            self.priority = 10
        else:
            self.priority = 0

    def takeTimeStep(self, position, activity, dt):
        transport = calculateTransport(position, self.position, speed, dt)
        if transport:
            return transport
        return position, "Work"
        

class GoalSleep(Goal):
    def __init__(self):
        self.name = "Sleep"
        self.position = (10,10)

    def setPriority(self, position, date):
        dt = transportTime(position, self.position)
        dateStart = datetime(date.year, date.month, date.day, 23, 0, 0) - timedelta(hours=dt)
        dateEnd = datetime(date.year, date.month, date.day, 7, 0, 0)
        if date >= dateStart or date < dateEnd:
            self.priority = 10
        else:
            self.priority = 0

    def takeTimeStep(self, position, activity, dt):
        transport = calculateTransport(position, self.position, speed, dt)
        if transport:
            return transport
        return position, "Sleep"

class GoalIdle(Goal):
    def __init__(self):
        self.name = "Idle"
        self.position = (10,10)

    def setPriority(self, position, date):
        self.priority = 1

    def takeTimeStep(self, position, activity, dt):
        transport = calculateTransport(position, self.position, speed, dt)
        if transport:
            return transport
        return position, "Idle"
